<?php

namespace App\Services\Gaode;


class GaoDeService
{
    protected $key = '7d4f1ddf86b52554671217830123cd5b'; //高德key
    protected $url = 'https://restapi.amap.com/v3/'; //高德url

    /**
     *根据位置获取经纬度
     * @param $address
     *author:tangfen
     *date:$ct
     */
    public function getAddressLocation($address)
    {
        $res = file_get_contents($this->url.'geocode/geo?key=' . $this->key . '&address=' . $address);
        $data = json_decode($res, TRUE);
        if ($data['info'] = 'OK') {
            return $data;
        } else {
            return false;
        }
    }

    /**
     *根据IP获取位置
     * @param $address
     *author:tangfen
     *date:$ct
     */
    public function beIpGetLocation($ip)
    {
        $res = file_get_contents($this->url.'geocode/regeo?key=' . $this->key . '&location=' . $ip);
        $data = json_decode($res, TRUE);
        if ($data['info'] = 'OK') {
            return $data;
        } else {
            return false;
        }
    }


}
